from common.libs.Helper import date_format

# coding=utf-8
def create_ccoupon_json(costomer_coupon, key_list=[], sc={}) :
    json = {}
    if "id" in key_list :
        json["id"] = costomer_coupon.id
    if "c_id" in key_list :
        json["c_id"] = costomer_coupon.c_id
    if "sc_id" in key_list :
        json["sc_id"] = float(costomer_coupon.sc_id)
    if "is_used" in key_list :
        json["is_used"] = costomer_coupon.is_used
    if "is_valid" in key_list:
        json["is_valid"] = costomer_coupon.is_valid
    json["sc"] = sc
    return json

def create_scoupon_json(shop_coupon, key_list=[]) :
    json = {}
    if "id" in key_list :
        json["id"] = shop_coupon.id
    if "name" in key_list:
        json["name"] = shop_coupon.name
    if "start_time" in key_list:
        json["start_time"] = date_format(shop_coupon.start_time, "%Y-%m-%d")
    if "end_time" in key_list:
        json["end_time"] = date_format(shop_coupon.end_time, "%Y-%m-%d")
    if "time_type" in key_list :
        json["time_type"] = shop_coupon.time_type
    if "full_cash" in key_list :
        json["full_cash"] = float(shop_coupon.full_cash)
    if "minus_cash" in key_list :
        json["minus_cash"] = float(shop_coupon.minus_cash)
    if "cash_type" in key_list :
        json["cash_type"] = shop_coupon.cash_type
    if "created_time" in key_list :
        json["created_time"] = str(shop_coupon.created_time)
    if "updated_time" in key_list :
        json["updated_time"] = str(shop_coupon.updated_time)
    if "shop_id" in key_list :
        json["shop_id"] = str(shop_coupon.shop_id)
    return json

